package com.openbravo.pos.inventory;

import com.openbravo.basic.BasicException;
import com.openbravo.beans.JCalendarDialog;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.loader.SentenceList;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.data.user.EditorRecord;
import com.openbravo.format.Formats;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;
import com.openbravo.pos.forms.DataLogicSales;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.Document;

public class TaxEditor extends JPanel
  implements EditorRecord
{
  private Object m_oId;
  private SentenceList taxcatsent;
  private ComboBoxValModel taxcatmodel;
  private SentenceList taxcustcatsent;
  private ComboBoxValModel taxcustcatmodel;
  private SentenceList taxparentsent;
  private ComboBoxValModel taxparentmodel;
  private JButton btnValidFrom;
  private JCheckBox jCascade;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JLabel jLabel5;
  private JLabel jLabel6;
  private JLabel jLabel7;
  private JTextField jOrder;
  private JComboBox m_jCustTaxCategory;
  private JTextField m_jName;
  private JTextField m_jRate;
  private JComboBox m_jTaxCategory;
  private JComboBox m_jTaxParent;
  private JTextField txtValidFrom;

  public TaxEditor(AppView paramAppView, DirtyManager paramDirtyManager)
  {
    DataLogicSales localDataLogicSales = (DataLogicSales)paramAppView.getBean("com.openbravo.pos.forms.DataLogicSales");
    initComponents();
    this.taxcatsent = localDataLogicSales.getTaxCategoriesList();
    this.taxcatmodel = new ComboBoxValModel();
    this.taxcustcatsent = localDataLogicSales.getTaxCustCategoriesList();
    this.taxcustcatmodel = new ComboBoxValModel();
    this.taxparentsent = localDataLogicSales.getTaxList();
    this.taxparentmodel = new ComboBoxValModel();
    this.m_jName.getDocument().addDocumentListener(paramDirtyManager);
    this.m_jTaxCategory.addActionListener(paramDirtyManager);
    this.txtValidFrom.getDocument().addDocumentListener(paramDirtyManager);
    this.m_jCustTaxCategory.addActionListener(paramDirtyManager);
    this.m_jTaxParent.addActionListener(paramDirtyManager);
    this.m_jRate.getDocument().addDocumentListener(paramDirtyManager);
    this.jCascade.addActionListener(paramDirtyManager);
    this.jOrder.getDocument().addDocumentListener(paramDirtyManager);
    writeValueEOF();
  }

  public void activate()
    throws BasicException
  {
    List localList = this.taxcatsent.list();
    this.taxcatmodel = new ComboBoxValModel(localList);
    this.m_jTaxCategory.setModel(this.taxcatmodel);
    localList = this.taxcustcatsent.list();
    localList.add(0, null);
    this.taxcustcatmodel = new ComboBoxValModel(localList);
    this.m_jCustTaxCategory.setModel(this.taxcustcatmodel);
  }

  public void refresh()
  {
    Object localObject;
    try
    {
      localObject = this.taxparentsent.list();
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, AppLocal.getIntString("message.cannotloadlists"), localBasicException);
      localMessageInf.show(this);
      localObject = new ArrayList();
    }
    ((List)localObject).add(0, null);
    this.taxparentmodel = new ComboBoxValModel((List)localObject);
    this.m_jTaxParent.setModel(this.taxparentmodel);
  }

  public void writeValueEOF()
  {
    this.m_oId = null;
    this.m_jName.setText(null);
    this.taxcatmodel.setSelectedKey(null);
    this.txtValidFrom.setText(null);
    this.taxcustcatmodel.setSelectedKey(null);
    this.taxparentmodel.setSelectedKey(null);
    this.m_jRate.setText(null);
    this.jCascade.setSelected(false);
    this.jOrder.setText(null);
    this.m_jName.setEnabled(false);
    this.m_jTaxCategory.setEnabled(false);
    this.txtValidFrom.setEnabled(false);
    this.btnValidFrom.setEnabled(false);
    this.m_jCustTaxCategory.setEnabled(false);
    this.m_jTaxParent.setEnabled(false);
    this.m_jRate.setEnabled(false);
    this.jCascade.setEnabled(false);
    this.jOrder.setEnabled(false);
  }

  public void writeValueInsert()
  {
    this.m_oId = UUID.randomUUID().toString();
    this.m_jName.setText(null);
    this.taxcatmodel.setSelectedKey(null);
    this.txtValidFrom.setText(null);
    this.taxcustcatmodel.setSelectedKey(null);
    this.taxparentmodel.setSelectedKey(null);
    this.m_jRate.setText(null);
    this.jCascade.setSelected(false);
    this.jOrder.setText(null);
    this.m_jName.setEnabled(true);
    this.m_jTaxCategory.setEnabled(true);
    this.txtValidFrom.setEnabled(true);
    this.btnValidFrom.setEnabled(true);
    this.m_jCustTaxCategory.setEnabled(true);
    this.m_jTaxParent.setEnabled(true);
    this.m_jRate.setEnabled(true);
    this.jCascade.setEnabled(true);
    this.jOrder.setEnabled(true);
  }

  public void writeValueDelete(Object paramObject)
  {
    Object[] arrayOfObject = (Object[])(Object[])paramObject;
    this.m_oId = arrayOfObject[0];
    this.m_jName.setText(Formats.STRING.formatValue(arrayOfObject[1]));
    this.taxcatmodel.setSelectedKey(arrayOfObject[2]);
    this.txtValidFrom.setText(Formats.TIMESTAMP.formatValue(arrayOfObject[3]));
    this.taxcustcatmodel.setSelectedKey(arrayOfObject[4]);
    this.taxparentmodel.setSelectedKey(arrayOfObject[5]);
    this.m_jRate.setText(Formats.PERCENT.formatValue(arrayOfObject[6]));
    this.jCascade.setSelected(((Boolean)arrayOfObject[7]).booleanValue());
    this.jOrder.setText(Formats.INT.formatValue(arrayOfObject[8]));
    this.m_jName.setEnabled(false);
    this.m_jTaxCategory.setEnabled(false);
    this.txtValidFrom.setEnabled(false);
    this.btnValidFrom.setEnabled(false);
    this.m_jCustTaxCategory.setEnabled(false);
    this.m_jTaxParent.setEnabled(false);
    this.m_jRate.setEnabled(false);
    this.jCascade.setEnabled(false);
    this.jOrder.setEnabled(false);
  }

  public void writeValueEdit(Object paramObject)
  {
    Object[] arrayOfObject = (Object[])(Object[])paramObject;
    this.m_oId = arrayOfObject[0];
    this.m_jName.setText(Formats.STRING.formatValue(arrayOfObject[1]));
    this.taxcatmodel.setSelectedKey(arrayOfObject[2]);
    this.txtValidFrom.setText(Formats.TIMESTAMP.formatValue(arrayOfObject[3]));
    this.taxcustcatmodel.setSelectedKey(arrayOfObject[4]);
    this.taxparentmodel.setSelectedKey(arrayOfObject[5]);
    this.m_jRate.setText(Formats.PERCENT.formatValue(arrayOfObject[6]));
    this.jCascade.setSelected(((Boolean)arrayOfObject[7]).booleanValue());
    this.jOrder.setText(Formats.INT.formatValue(arrayOfObject[8]));
    this.m_jName.setEnabled(true);
    this.m_jTaxCategory.setEnabled(true);
    this.txtValidFrom.setEnabled(true);
    this.btnValidFrom.setEnabled(true);
    this.m_jCustTaxCategory.setEnabled(true);
    this.m_jTaxParent.setEnabled(true);
    this.m_jRate.setEnabled(true);
    this.jCascade.setEnabled(true);
    this.jOrder.setEnabled(true);
  }

  public Object createValue()
    throws BasicException
  {
    Object[] arrayOfObject = new Object[9];
    arrayOfObject[0] = this.m_oId;
    arrayOfObject[1] = this.m_jName.getText();
    arrayOfObject[2] = this.taxcatmodel.getSelectedKey();
    arrayOfObject[3] = Formats.TIMESTAMP.parseValue(this.txtValidFrom.getText());
    arrayOfObject[4] = this.taxcustcatmodel.getSelectedKey();
    arrayOfObject[5] = this.taxparentmodel.getSelectedKey();
    arrayOfObject[6] = Formats.PERCENT.parseValue(this.m_jRate.getText());
    arrayOfObject[7] = Boolean.valueOf(this.jCascade.isSelected());
    arrayOfObject[8] = Formats.INT.parseValue(this.jOrder.getText());
    return arrayOfObject;
  }

  public Component getComponent()
  {
    return this;
  }

  private void initComponents()
  {
    this.m_jName = new JTextField();
    this.jLabel2 = new JLabel();
    this.jLabel3 = new JLabel();
    this.m_jRate = new JTextField();
    this.jLabel1 = new JLabel();
    this.jLabel4 = new JLabel();
    this.jLabel5 = new JLabel();
    this.jCascade = new JCheckBox();
    this.m_jTaxCategory = new JComboBox();
    this.m_jTaxParent = new JComboBox();
    this.m_jCustTaxCategory = new JComboBox();
    this.jLabel6 = new JLabel();
    this.jOrder = new JTextField();
    this.jLabel7 = new JLabel();
    this.txtValidFrom = new JTextField();
    this.btnValidFrom = new JButton();
    setLayout(null);
    add(this.m_jName);
    this.m_jName.setBounds(240, 20, 200, 19);
    this.jLabel2.setText(AppLocal.getIntString("Label.Name"));
    add(this.jLabel2);
    this.jLabel2.setBounds(20, 20, 220, 15);
    this.jLabel3.setText(AppLocal.getIntString("label.dutyrate"));
    add(this.jLabel3);
    this.jLabel3.setBounds(20, 170, 220, 15);
    add(this.m_jRate);
    this.m_jRate.setBounds(240, 170, 60, 19);
    this.jLabel1.setText(AppLocal.getIntString("label.taxcategory"));
    add(this.jLabel1);
    this.jLabel1.setBounds(20, 50, 220, 15);
    this.jLabel4.setText(AppLocal.getIntString("label.custtaxcategory"));
    add(this.jLabel4);
    this.jLabel4.setBounds(20, 110, 220, 15);
    this.jLabel5.setText(AppLocal.getIntString("label.taxparent"));
    add(this.jLabel5);
    this.jLabel5.setBounds(20, 140, 220, 15);
    this.jCascade.setText(AppLocal.getIntString("label.cascade"));
    add(this.jCascade);
    this.jCascade.setBounds(320, 170, 110, 23);
    add(this.m_jTaxCategory);
    this.m_jTaxCategory.setBounds(240, 50, 200, 24);
    add(this.m_jTaxParent);
    this.m_jTaxParent.setBounds(240, 140, 200, 24);
    add(this.m_jCustTaxCategory);
    this.m_jCustTaxCategory.setBounds(240, 110, 200, 24);
    this.jLabel6.setText(AppLocal.getIntString("label.order"));
    add(this.jLabel6);
    this.jLabel6.setBounds(20, 200, 220, 15);
    add(this.jOrder);
    this.jOrder.setBounds(240, 200, 60, 19);
    this.jLabel7.setText(AppLocal.getIntString("Label.ValidFrom"));
    add(this.jLabel7);
    this.jLabel7.setBounds(20, 80, 120, 15);
    add(this.txtValidFrom);
    this.txtValidFrom.setBounds(240, 80, 200, 19);
    this.btnValidFrom.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/date.png")));
    this.btnValidFrom.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        TaxEditor.this.btnValidFromActionPerformed(paramActionEvent);
      }
    });
    add(this.btnValidFrom);
    this.btnValidFrom.setBounds(450, 80, 50, 26);
  }

  private void btnValidFromActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      localDate = (Date)Formats.TIMESTAMP.parseValue(this.txtValidFrom.getText());
    }
    catch (BasicException localBasicException)
    {
      localDate = null;
    }
    Date localDate = JCalendarDialog.showCalendarTimeHours(this, localDate);
    if (localDate != null)
      this.txtValidFrom.setText(Formats.TIMESTAMP.formatValue(localDate));
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.inventory.TaxEditor
 * JD-Core Version:    0.6.0
 */